/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Form;

import data.ManagerDatabase;
import java.io.File;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author GREENWIND
 */
public class SaveData extends JFrame{
    ManagerDatabase db;
    public SaveData(ManagerDatabase database)
    {
        db = database;
    }
    public void Save()
    {
        File f = new File("database/"+db.GetName()+".JSQL");
        if(f.exists())
        {
            int kq=  JOptionPane.showConfirmDialog(rootPane, 
                            "File name database is exist, do you want to override it? ", "Warning",JOptionPane.YES_NO_OPTION);
            if(kq == 0)
            {
               f.delete();
               db.saveAllTable("database/"+db.GetName()+".JSQL"); 
            }
            else
            {
                return;
            }
        }
        else
        {
            db.saveAllTable(f.getAbsolutePath());
            JOptionPane.showMessageDialog(rootPane,
                   "Save database "+ db.GetName()+" success", "Success", WIDTH);
        }
        
        
    }
    
    
}
